﻿using System.Web.Mvc;
using ComeSeeThis_MVC2.Models;

namespace ComeSeeThis_MVC2.Controllers
{
    public class ProductsAdminController : Controller
    {
        #region Index

        [Authorize(Roles = ("SiteAdmin"))]
        public ActionResult Index()
        {
            return View();
        }

        #endregion

        #region Company

        // ReSharper disable InconsistentNaming
        readonly CompanyRepository companyRepository = new CompanyRepository();
        // ReSharper restore InconsistentNaming

        public ActionResult Company()
        {
            var companies = companyRepository.GetAllCompanies(2, ProductType.All);

            return View(companies);
        }

        #endregion

        #region Vehicle

        // ReSharper disable InconsistentNaming
        readonly VehicleRepository vehicleRepository = new VehicleRepository();
        // ReSharper restore InconsistentNaming

        public ActionResult Vehicle()
        {
            var vehicles = vehicleRepository.GetAllVehicles(false, false);

            return View(vehicles);
        }

        public ActionResult VehicleEdit(int id)
        {
            var vehicle = vehicleRepository.GetVehicle(id);
            return View(new VehicleFormView(vehicle));
        }

        public ActionResult VehicleApprove(int id)
        {
            var vehicle = vehicleRepository.GetVehicle(id);
            vehicle.Approved = true;

            if (TryUpdateModel(vehicle))
            {
                vehicleRepository.Save();

            }
            return RedirectToAction("Vehicle");
        }
        #endregion

    }
}
